package org.example.threadpool;

import lombok.extern.slf4j.Slf4j;
import org.example.utils.Sleeper;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author zhengdp
 * @Description 线程池关闭相关的方法测试
 * @Date 2022/12/13 23:00
 * @Created by zhengdp
 */
@Slf4j(topic = "c.TestShutdown")
public class TestShutdown {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(2);

        Future<Integer> result = pool.submit(() -> {
            log.info(" task 1 running ...");
            Sleeper.sleep(1000);
            log.info(" task 1 finish ...");
            return 1;
        });

        Future<Integer> result2 = pool.submit(() -> {
            log.info(" task 2 running ...");
            Sleeper.sleep(1000);
            log.info(" task 2 finish ...");
            return 2;
        });

        Future<Integer> result3 = pool.submit(() -> {
            log.info(" task 3 running ...");
            Sleeper.sleep(1000);
            log.info(" task 3 finish ...");
            return 3;
        });

        log.info("shutdownNow");
        List<Runnable> runnables = pool.shutdownNow();
        log.info("other ... {} ",runnables);
        runnables.forEach(Runnable::run);

    }
}
